/*
 * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum ingilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package cn.itenzo.common.validate;

import com.baidu.unbiz.fluentvalidator.Validator;
import com.baidu.unbiz.fluentvalidator.ValidatorContext;
import com.baidu.unbiz.fluentvalidator.ValidatorHandler;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 金额不能为0开头或者0
 * Created by ENZO on 2017/4/12.
 */
public class MoneyFenValidate extends ValidatorHandler<String> implements Validator<String> {

	@Override
	public boolean validate(ValidatorContext context, String s) {
		
		if(null == s || "".equals(s)){

			context.addErrorMsg("金额不能为空");
			return false;
		}

		Pattern pattern = Pattern.compile("^([1-9][0-9]*)$");
		Matcher match = pattern.matcher(s);
		if (!match.matches()) {

			context.addErrorMsg(String.format("%s，不是有效金额", s));
			return false;
		}

		return true;
	}
}
